package com.zhentao.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhentao.pojo.TcCountdownEvent;
import com.zhentao.service.TcCountdownEventService;
import com.zhentao.mapper.TcCountdownEventMapper;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;

/**
 * 倒数日事件表Service实现类
 * 
 * @author zhentao
 */
@Service
public class TcCountdownEventServiceImpl extends ServiceImpl<TcCountdownEventMapper, TcCountdownEvent>
    implements TcCountdownEventService {

    @Override
    public List<TcCountdownEvent> getByCreator(String creator) {
        QueryWrapper<TcCountdownEvent> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("creator", creator);
        queryWrapper.orderByDesc("create_time");
        return list(queryWrapper);
    }

    @Override
    public List<TcCountdownEvent> getUpcomingEvents() {
        QueryWrapper<TcCountdownEvent> queryWrapper = new QueryWrapper<>();
        LocalDate sevenDaysLater = LocalDate.now().plusDays(7);
        queryWrapper.ge("target_date", LocalDate.now());
        queryWrapper.le("target_date", sevenDaysLater);
        queryWrapper.orderByAsc("target_date");
        return list(queryWrapper);
    }

    @Override
    public List<TcCountdownEvent> getExpiredEvents() {
        QueryWrapper<TcCountdownEvent> queryWrapper = new QueryWrapper<>();
        queryWrapper.lt("target_date", LocalDate.now());
        queryWrapper.orderByDesc("target_date");
        return list(queryWrapper);
    }
}

